package com.ujiuye.service;

import com.ujiuye.dao.StudentDao;
import com.ujiuye.pojo.Student;
import com.ujiuye.utils.PageTools;

import java.util.List;

public class StudentService {
    private StudentDao studentDao = new StudentDao();
    //查询所有学生
    public List<Student> queryAllStudent() {
        return studentDao.queryAllStudent();
    }

    //查询总条数
    public int queryAllSize() {
        return studentDao.queryAllSize();
    }

    //分页查询
    public List<Student> dimQueryStudent(PageTools pt) {
        return studentDao.dimQueryStudent(pt);
    }


    //模糊分页
    public PageTools dimQueryStudentByPage(String pageSize, String currentPage, String sname) {
        //处理参数   当前页  每页显示的条数
        int ps;
        if(pageSize == null || "".equals(pageSize)) {
            ps = 3;
        }else {
            ps = Integer.parseInt(pageSize);
        }

        int cp;
        if(currentPage == null || "".equals(currentPage)) {
            cp = 1;
        }else {
            cp = Integer.parseInt(currentPage);
        }

        //查询总条数   带上sname条件
        int sumSize = studentDao.querySizeBySname(sname);


        //封装工具类
        PageTools pt = new PageTools(cp,ps,sumSize);


        //通过工具类去查询对应的学生信息  list
        List<Student> lists = studentDao.queryStudentBySname(pt,sname);

        //把list集合放到工具类里面
        pt.setStudentList(lists);

        //把工具类返回给servlet
        return pt;

    }
}
